/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.awsmanager.common;

import com.awsmanager.utils.ProcessXML;
import com.sun.data.provider.impl.ObjectListDataProvider;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

/**
 *
 * @author sodell
 */
public class S3StorageServerDataProvider extends ObjectListDataProvider {
    private ArrayList<String> s3Servers = new ArrayList();;
    private HashMap s3ServersInfo = new HashMap();

    public S3StorageServerDataProvider() {
        setList(s3Servers);
        setObjectType(S3StorageServer.class);
    }

    public HashMap getS3ServersMap() {
        return s3ServersInfo;
    }

    public String parseXmlString(String xmlString) {
        ProcessXML xmlInfo = new ProcessXML(xmlString, "S3ServerInfo");
        String errorMsg = xmlInfo.getErrorMsg();

        if (errorMsg != null) {
            return errorMsg;
        }

        if (xmlInfo.getXmlNodes() == null) {
            return null;
        }

        Collection xmlNodes = xmlInfo.getXmlNodes().values();

        //obtain an Iterator for Collection
        Iterator itr = xmlNodes.iterator();

        //iterate through HashMap values iterator
        while (itr.hasNext()) {
            S3StorageServer s3Server = (S3StorageServer) itr.next();
            s3ServersInfo.put(s3Server.getS3Server(), s3Server);
        }
        return errorMsg;
    }
}